package com.hadoop.test;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class MaxTemperatureMapper extends Mapper<LongWritable, Text, Text, IntWritable> {

    private NcdcRecordParser ncdcRecordParser = new NcdcRecordParser();

    @Override
    public void map(LongWritable key, Text value, Context context) throws InterruptedException, IOException {
        /*String line = value.toString();
        String year = line.substring(15, 19);
        int airTemperature = Integer.parseInt(line.substring(87, 92));
        context.write(new Text(year), new IntWritable(airTemperature));*/

        ncdcRecordParser.parse(value);
        if(ncdcRecordParser.isValidTemperature()){
            context.write(new Text(ncdcRecordParser.getYear()),new IntWritable(ncdcRecordParser.getAirTemperature()));
        }
    }
}
